package com.qf.controller;

import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/category")
public class AdminCategoryController {

    @Autowired
    DtsCategoryService categoryService;

    @PostMapping("/update")
    public Object update(@RequestBody DtsCategory category){
        categoryService.update(category);

        return ResponseUtil.ok();

    }

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsCategory category){
        categoryService.delete(category);

        return ResponseUtil.ok();

    }
    @PostMapping("/create")
    public Object create(@RequestBody DtsCategory category){
        categoryService.insert(category);

        return ResponseUtil.ok();

    }
    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "20")Integer limit,
                       @RequestParam(value = "sort",required = false,defaultValue = "add_time")String sort,
                       @RequestParam(value = "order",required = false,defaultValue = "desc")String order,
                       Integer id,String name){

        Map<String, Object> data = categoryService.findByPage(page,limit,sort,order,id,name);

        return ResponseUtil.ok(data);

    }
}
